如何实现 Python 中 selnium 模块的换行 您所在的位置:网站首页 selenium 回车 如何实现 Python 中 selnium 模块的换行

如何实现 Python 中 selnium 模块的换行

2023-08-14 15:40| 来源: 网络整理| 查看: 265

如何实现 Python 中 selnium 模块的换行 三种方法: 直接调用 .submit() 方法,常使用在用户密码登录中

# driver.find_element_by_xpath('//*[@id="tree-finder-field"]').submit()

使用系统换行符,缺陷受限

# driver.find_element_by_xpath('//*[@id="tree-finder-field"]').send_keys('\r\n','\n')

Text files created on DOS/Windows machines have different line endings than files created on Unix/Linux. DOS uses carriage return and line feed ("\r\n") as a line ending, which Unix uses just line feed ("\n"). You need to be careful about transferring files between Windows machines and Unix machines to make sure the line endings are translated properly.

调用自带类,键盘模拟种类全 from selenium.webdriver.common.keys import Keys driver.find_element_by_xpath('//*[@id="login"]/form/div[4]/input[3]').send_keys(Keys.ENTER)

但是!不管使用哪种方法,都需要 time.sleep 让系统停下会,不然永远不生效(尤其是信息搜索的时候)

参考: http://www.cs.toronto.edu/~krueger/csc209h/tut/line-endings.html https://stackoverflow.com/

该小技巧使用在lctt-cli项目



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有